home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / srcuc.zip / SYSPRIM.C < prev    next >
C/C++ Source or Header  |  1991-08-26  |  5KB  |  159 lines

  1. /* -*-C-*-
  2.  
  3. $Header: /zu/arthur/amb/850/microcode/RCS/sysprim.c,v 9.36 1991/08/26 15:00:18 arthur Exp $
  4.  
  5. Copyright (c) 1987, 1988, 1989, 1990, 1991 Massachusetts Institute of Technology
  6.  
  7. This material was developed by the Scheme project at the Massachusetts
  8. Institute of Technology, Department of Electrical Engineering and
  9. Computer Science.  Permission to copy this software, to redistribute
  10. it, and to use it for any purpose is granted, subject to the following
  11. restrictions and understandings.
  12.  
  13. 1. Any copy made of this software must include this copyright notice
  14. in full.
  15.  
  16. 2. Users of this software agree to make their best efforts (a) to
  17. return to the MIT Scheme project any improvements or extensions that
  18. they make, so that these may be included in future releases; and (b)
  19. to inform MIT of noteworthy uses of this software.
  20.  
  21. 3. All materials developed as a consequence of the use of this
  22. software shall duly acknowledge such use, in accordance with the usual
  23. standards of acknowledging credit in academic research.
  24.  
  25. 4. MIT has made no warrantee or representation that the operation of
  26. this software will be error-free, and MIT is under no obligation to
  27. provide any services, by way of maintenance, update, or otherwise.
  28.  
  29. 5. In conjunction with products arising from the use of this material,
  30. there shall be no use of the name of the Massachusetts Institute of
  31. Technology nor of any adaptation thereof in any advertising,
  32. promotional, or sales literature without prior written consent from
  33. MIT in each case. */
  34.  
  35. /* Random system primitives.  Most are implemented in terms of
  36.    utilities in os.c */
  37.  
  38. #include "scheme.h"
  39. #include "prims.h"
  40. #include "ostty.h"
  41. #include "ostop.h"
  42.  
  43. /* Pretty random primitives */
  44.  
  45. DEFINE_PRIMITIVE ("EXIT", Prim_non_restartable_exit, 0, 0,
  46.   "Exit Scheme with no option to restart.")
  47. {
  48.   PRIMITIVE_HEADER (0);
  49.   termination_normal (0);
  50. }
  51.  
  52. DEFINE_PRIMITIVE ("EXIT-WITH-VALUE", 
  53.           Prim_non_restartable_exit_with_value, 1, 1,
  54.   "Exit Scheme with no option to restart, returning integer argument\n\
  55. as exit status.")
  56. {
  57.   PRIMITIVE_HEADER (1);
  58.   termination_normal ((int) arg_integer (1));
  59. }
  60.  
  61. DEFINE_PRIMITIVE ("HALT", Prim_restartable_exit, 0, 0,
  62.   "Exit Scheme, suspending it to that it can be restarted.")
  63. {
  64.   PRIMITIVE_HEADER (0);
  65.   OS_restartable_exit ();
  66. }
  67.  
  68. DEFINE_PRIMITIVE ("UNDER-EMACS?", Prim_under_emacs_p, 0, 0, 0)
  69. {
  70.   PRIMITIVE_HEADER (0);
  71.   PRIMITIVE_RETURN (BOOLEAN_TO_OBJECT (OS_under_emacs_p ()));
  72. }
  73.  
  74. /* (SET-RUN-LIGHT! OBJECT)
  75.    On the HP Pascal workstation system, it allows the character
  76.    displayed in the lower right-hand part of the screen to be changed.
  77.    In CScheme, rings the bell.
  78.    Used by various things to indicate the state of the system. */
  79.  
  80. DEFINE_PRIMITIVE ("SET-RUN-LIGHT!", Prim_set_run_light, 1, 1, 0)
  81. {
  82.   PRIMITIVE_HEADER (1);
  83. #ifdef RUN_LIGHT_IS_BEEP
  84.   fputs ((OS_tty_command_beep ()), stdout);
  85.   fflush (stdout);
  86.   PRIMITIVE_RETURN (SHARP_T);
  87. #else
  88.   PRIMITIVE_RETURN (SHARP_F);
  89. #endif
  90. }
  91.  
  92. #define CONVERT_ADDRESS(address)                    \
  93.   (long_to_integer (ADDRESS_TO_DATUM (address)))
  94.  
  95. DEFINE_PRIMITIVE ("GC-SPACE-STATUS", Prim_gc_space_status, 0, 0, 0)
  96. {
  97.   SCHEME_OBJECT * constant_low;
  98.   SCHEME_OBJECT * constant_free;
  99.   SCHEME_OBJECT * constant_high;
  100.   SCHEME_OBJECT * heap_low;
  101.   SCHEME_OBJECT * heap_free;
  102.   SCHEME_OBJECT * heap_limit;
  103.   SCHEME_OBJECT * heap_high;
  104. #ifndef USE_STACKLETS
  105.   SCHEME_OBJECT * stack_low;
  106.   SCHEME_OBJECT * stack_free;
  107.   SCHEME_OBJECT * stack_limit;
  108.   SCHEME_OBJECT * stack_high;
  109. #endif /* USE_STACKLETS */
  110.   SCHEME_OBJECT result;
  111.   PRIMITIVE_HEADER (0);
  112.  
  113.   constant_low = Constant_Space;
  114.   constant_free = Free_Constant;
  115.   constant_high = Constant_Top;
  116.   heap_low = Heap_Bottom;
  117.   heap_free = Free;
  118.   heap_limit = MemTop;
  119.   heap_high = Heap_Top;
  120. #ifndef USE_STACKLETS
  121.   stack_low = Absolute_Stack_Base;
  122.   stack_free = Stack_Pointer;
  123.   stack_limit = Stack_Guard;
  124.   stack_high = Stack_Top;
  125. #endif /* USE_STACKLETS */
  126.  
  127.   result = (make_vector (12, SHARP_F, true));
  128.   VECTOR_SET (result, 0, (LONG_TO_UNSIGNED_FIXNUM (sizeof (SCHEME_OBJECT))));
  129.   VECTOR_SET (result, 1, (CONVERT_ADDRESS (constant_low)));
  130.   VECTOR_SET (result, 2, (CONVERT_ADDRESS (constant_free)));
  131.   VECTOR_SET (result, 3, (CONVERT_ADDRESS (constant_high)));
  132.   VECTOR_SET (result, 4, (CONVERT_ADDRESS (heap_low)));
  133.   VECTOR_SET (result, 5, (CONVERT_ADDRESS (heap_free)));
  134.   VECTOR_SET (result, 6, (CONVERT_ADDRESS (heap_limit)));
  135.   VECTOR_SET (result, 7, (CONVERT_ADDRESS (heap_high)));
  136. #ifndef USE_STACKLETS
  137.   VECTOR_SET (result, 8, (CONVERT_ADDRESS (stack_low)));
  138.   VECTOR_SET (result, 9, (CONVERT_ADDRESS (stack_free)));
  139.   VECTOR_SET (result, 10, (CONVERT_ADDRESS (stack_limit)));
  140.   VECTOR_SET (result, 11, (CONVERT_ADDRESS (stack_high)));
  141. #endif /* USE_STACKLETS */
  142.   PRIMITIVE_RETURN (result);
  143. }
  144.  
  145. DEFINE_PRIMITIVE ("SET-TRAP-STATE!", Prim_set_trap_state, 1, 1, 0)
  146. {
  147.   long result;
  148.   extern long OS_set_trap_state();
  149.   PRIMITIVE_HEADER (1);
  150.  
  151.   result = (OS_set_trap_state (arg_nonnegative_integer (1)));
  152.   if (result < 0)
  153.   {
  154.     error_bad_range_arg (1);
  155.     /*NOTREACHED*/
  156.   }
  157.   PRIMITIVE_RETURN (LONG_TO_UNSIGNED_FIXNUM (result));
  158. }
  159.